import React from "react";
import Mock from "mockjs";
import axios from "axios";

Mock.mock("/list", {
  "list|10": [
    {
      name: "@cname",
      "age|10-20": 1,
      "sex|1": ["男", "女"],
    },
  ],
});

class Comp1 extends React.Component {
  state = {
    list: [],
  };
  async getList() {
    const resp = await axios.get("/list");
    console.log(resp.data.list);
    // 保存数据
    this.setState({
      list: resp.data.list,
    });
  }
  getList1() {
    axios.get("/list").then((resp) => {
      this.setState({
        list: resp.data.list,
      });
    });
  }
  render() {
    const { list } = this.state;
    return (
      <div>
        <div>Comp1 组件s</div>
        <ul>
          {list.map((v, i) => {
            return (
              <li key={i}>
                姓名：{v.name} 年龄：{v.age} 性别： {v.sex}
              </li>
            );
          })}
        </ul>
      </div>
    );
  }
  componentDidMount() {
    this.getList();
  }
}

export default Comp1;
